﻿
@{
    ViewBag.Title = "BizTypeAdd";
    Layout = "~/Views/Shared/layoutCommon.cshtml";
}
@model OF.Component.Model.ExpressCompanyInfo

@section style{
    <link href="~/lib/bootstrap-fileinput/css/fileinput.min.css" rel="stylesheet" />
    <style>
        .form-horizontal .control-label {
            width: 20%;
            float: left;
            text-align: right;
        }

        .col-sm-3 {
            width: 80%;
            float: left;
        }
         /*插件css写了字号999会导致文字闪动一下。此样式为覆盖插件的css*/
        .file-loading {
            font-size: small;
        }
    </style>
}
<form id="form1" class="form-horizontal">
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">快递名称：</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" value="@Model.CompanyName" style="width:300px;" name="txtName" maxlength="50" id="txtName" />
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">LOGO：</label>
                        <div class="col-sm-3">
                            <div style="width:50%">
                                <input type="file" name="txt_file" id="txt_file" style="width:300px;" class="file-loading" />
                                @*上传成功后接口返回数据，此处用于存文件名*@
                                <input type="hidden" id="resData" />
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-footer text-center">
                    <button class="btn btn-primary" type="button" id="btnSave">确 定 </button>
                    <button class="btn" type="button" id="cancel">取 消 </button>
                </div>
            </div>

        </div>
        <!-- /.row -->
    </section>

</form>
@section scriptsBottom{
    <script src="~/lib/bootstrap-fileinput/js/fileinput.min.js"></script>
    <script src="~/lib/bootstrap-fileinput/js/fileinput_locale_zh.js"></script>
    <script src="~/js/fileinput_img.js"></script>
    <script type="text/javascript">
       $(document).ready(function () {
           initFormValidate();
           var oFileInput = new FileInput();
           oFileInput.Init("txt_file", "@Url.Action("UploadImg", "BasicData")");
           $("#btnSave").click(function(){
               save();
           });
           $("#cancel").click(function () {
               BMCW.closeTopLayer();
           });
       });
       function initFormValidate() {
           $("#form1").bootstrapValidator({
               submitHandler: function (valiadtor, loginForm, submitButton) {
                   valiadtor.defaultSubmit();
               },
               fields: {
                   txtName: {
                       validators: {
                           notEmpty: {
                               message: '快递名称不能为空'
                           },
                           stringLength: {
                               /*长度提示*/
                               min: 1,
                               max: 50,
                               message: '名称长度必须在1到50之间'
                           }
                       }
                   }
               }
           });
       }

       function save()
       {
           var bootstrapValidator = $("#form1").data('bootstrapValidator');
           bootstrapValidator.validate();

           if (bootstrapValidator.isValid()) {
               var url = '@Url.Action("ExpressSave", "BasicData")'
               //LOGO只存文件名，前缀存储位置写入配置文件固定
               BMCW.ajax({
                   url: url,
                   type: "Post",
                   data: {
                       ExpressCompanyID:@Model.ExpressCompanyID,
                       CompanyName: $("#txtName").val(),
                       Logo: $("#resData").val()
                   },
                   success: function (o) {
                       if (o.status == 0) {
                           BMCW.msg("保存成功",function(){
                               BMCW.getTopSelectedWin().search();
                           });
                       } else {
                           BMCW.alert("保存失败");
                       }
                   }
               });
           }
        }
    </script>
}

